package com.projecy.storehouse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.projecy.storehouse.dao.TheShowDao;
import com.projecy.storehouse.entity.ProductUnit;
import com.projecy.storehouse.entity.TheLibrary;
import com.projecy.storehouse.entity.dto.UpdatePutRegister;
import com.projecy.storehouse.service.*;
import com.projecy.storehouse.util.RepertoryResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 出库登记
 * author: mao yi
 * date: 2023/3/28
 * OutRegister:
 */
@RestController
@RequestMapping("sys")
public class OutRegisterController {


    @Autowired
    TheLibraryService theLibraryService;

    @Autowired
    TheLibraryDefaultService theLibraryDefaultService;

    @Autowired
    ProductUnitService productUnitService;

    /**
     * 查询说有已调度的入库信息
     * @param reason
     * @return
     */
    @GetMapping("/outRegister/list1/{reason}/{current}")
    public ResponseEntity<Object> seachOutDispatch(@PathVariable String reason){
        return RepertoryResultUtil.success(true,theLibraryService.seacherTheLibraryDispatchMark(reason,"已调度"));
    };

    /**
     * @GetMapping("/outStorage/list1/{putId}")
     */

    /**
     * 查询库存
     * @param productId
     * @return
     */
    @GetMapping("/outRegister/reserves/{productId}")
    public ResponseEntity<Object> reservesOutRegister(@PathVariable Long productId){
        return RepertoryResultUtil.success(true,productUnitService.getOne(new QueryWrapper<ProductUnit>().eq("product_id",productId)));
    }

    /**
     * 提交申请
     * @param list
     * @return
     */
    @PostMapping("/outRegister/updatePutRegister")
    public ResponseEntity<Object> updateOutRegister(@RequestBody UpdatePutRegister list){
        return theLibraryService.updateOutRegister(list);
    }

    /**
     * 查询所以待登记
     * @return
     */
    @GetMapping("/outRegister/list1")
    public ResponseEntity<Object> selectAllOut(){
        return RepertoryResultUtil.success(true,theLibraryService.list(new QueryWrapper<TheLibrary>().eq("out_register_mark","待登记")));
    }

    /**
     * @GetMapping("/outStorage/list1/{putId}")
     */

    /**
     * 复核
     * @param putId
     * @return
     */
    @PostMapping("/outRegister/checkAndAdd/{putId}")
    public  ResponseEntity<Object> outCheckAndAdd(@PathVariable Long putId){
        return theLibraryService.outCheckAndAdd(putId);
    }

    /**
     * 查询所有入库信息
     * @return
     */
    @GetMapping("/outRegister/list")
    public ResponseEntity<Object> selectAllOutRegister(){
        return RepertoryResultUtil.success(true,theLibraryService.list(new QueryWrapper<TheLibrary>().eq("out_warehousing_mark","已完成")));
    }

    @Autowired
    TheShowDao theShowDao;

    @GetMapping("/outRegister/list/one/{putId}")
    public ResponseEntity<Object> selectAllOutRegister(@PathVariable Long putId){
        return RepertoryResultUtil.success(true,theShowDao.selectList(null));
    }



}
